package com.dhcc.DRGsHosp.application.impl;

import java.util.List;
import java.util.Set;

import javax.inject.Named;

import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.QueryChannelService;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.DRGsHosp.application.DrgsVersionManageApplication;
import com.dhcc.DRGsHosp.core.domain.DrgsVersionManage;


@Named
@Transactional
public class DrgsVersionManageApplicationImpl implements DrgsVersionManageApplication{
	
	
	private QueryChannelService queryChannel;
	
    private QueryChannelService getQueryChannelService(){
       if(queryChannel==null){
          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
       }
     return queryChannel;
    }
	
    public DrgsVersionManage getDrgsVersionManage(String verCode) {
		return DrgsVersionManage.get(DrgsVersionManage.class, verCode);
	}
	
	public void creatDrgsVersionManage(DrgsVersionManage dvm) {
		dvm.save();
	}
	
	public void updateDrgsVersionManage(DrgsVersionManage dvm) {
		dvm .save();
	}
	
	public void removeDrgsVersionManage(DrgsVersionManage dvm) {
		if(dvm != null){
			dvm.remove();
		}
	}
	
	public void removeDrgsVersionManages(Set<DrgsVersionManage> dvms) {
		for (DrgsVersionManage dvm : dvms) {
			dvm.remove();
		}
	}
    
    
	/**  
	 *  @Description：获取全部DRG版本管理信息
	 *  @Author huangju  
	 *  @see com.dhcc.DRGsHosp.application.DrgsVersionManageApplication#findAllDrgsVersionManage()  
	 */
	@Override
	public List<DrgsVersionManage> findAllDrgsVersionManage() {
		return DrgsVersionManage.findAll(DrgsVersionManage.class);
	}
	
	/**
     *  
     *  isHospOrderExist.  
     *  @Description：院区编码是否存在
     *  @Author fulianxia
     *  @param hospOrder
     *  @return 
     *  @Date:2018年3月26日
     */
	@Override
	public boolean isVerOrderExist(String verCode) {
		String sql = "select count(1) from drgs.t_drgversion t where  " ;
		if(verCode != null){
			sql += " t.ver_code <> '"+verCode+"'";
		}
		Integer count = Integer.parseInt(getQueryChannelService().createSqlQuery(sql).singleResult().toString()) ;
		if( count == 0 ) {
			return false ;
		} 
		return true;
	}

	

}
